<?php

namespace app\models;

use Yii;
use yii\behaviors\TimestampBehavior;
/**
 * This is the model class for table "asr_customer".
 *
 * @property int $customer_id 用户电话号码的列表自增ID
 * @property string $username 用户姓名
 * @property int $phone_num 用户电话
 * @property string $company_name 公司名称
 * @property string $job 人员职位
 * @property string $address 地址
 * @property string $remark 备注
 * @property int $sex 性别1男,2女
 * @property int $mobile_id asr_mobile外键关联表的Id
 *
 * @property AsrMobile $mobile
 */
class AsrCustomer extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'asr_customer';
    }

    public function behaviors()
    {
        return [
            TimestampBehavior::className()
        ];
    }
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['mobile_id'], 'integer'],
            ['phone_num', 'integer'],
//            ['phone_num', 'unique','message' => '上传的号码存在重复或者数据库中已经存在！'],
            [['username', 'job', 'address'], 'string', 'max' => 50],
            [['company_name'], 'string', 'max' => 40],
            [['remark'], 'string', 'max' => 255],
            [['sex'], 'string', 'max' => 2],
            [['mobile_id'], 'exist', 'skipOnError' => true, 'targetClass' => AsrMobile::className(), 'targetAttribute' => ['mobile_id' => 'mobile_id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'customer_id' => 'Customer ID',
            'username' => '用户姓名',
            'phone_num' => '用户电话',
            'company_name' => '公司名称',
            'job' => '工作职位',
            'address' => '用户地址',
            'remark' => '备注',
            'sex' => '性别',
            'mobile_id' => 'Mobile ID',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     * 关联asr_mobile
     */
//    public function getMobile()
//    {
//        return $this->hasOne(AsrMobile::className(), ['mobile_id' => 'mobile_id']);
//    }

    /**
     * @return \yii\db\ActiveQuery
     * 关联asr_call_classify
     */
    public function getAsrCallClassify()
    {
        return $this->hasOne(AsrCallClassify::className(), ['customer_id' => 'customer_id']);
    }
}
